import { Task } from '@app/models/task'
import { FindManyOptions } from 'typeorm'

const Tasks = new class {
    async first() {
        const options: FindManyOptions = {
            where: {done: false},
            order: {id: 'ASC'}
        }
        return await Task.findOne(options)
    }

    async get(id: number) {
        return Task.findOne({id: id})
    }

    async setDone(id: number, count: number) {
        return await Task.getRepository().update({id: id}, {done: true, count})
    }
}()

export { Tasks }
